package com.muti.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.MessageChannels;

/**
 * Author:yang
 * Date:2024-03-05 21:43
 * 配置类：配置消息通道和处理器
 */
@Configuration
public class MessageConfig {

    // 点对点模型的消息通道
    @Bean
    public DirectChannel pointToPointChannel() {
        return MessageChannels.direct().get();
    }

    // 发布订阅模型的消息通道
    @Bean
    public PublishSubscribeChannel publishSubscribeChannel() {
        return MessageChannels.publishSubscribe().get();
    }

    // 点对点消息处理器
    @Bean
    public IntegrationFlow pointToPointFlow() {
        return IntegrationFlows.from("pointToPointChannel")
                .handle("pointToPointMessageHandler", "handleMessage")
                .get();
    }

    // 发布订阅消息处理器
    @Bean
    public IntegrationFlow publishSubscribeFlow() {
        return IntegrationFlows.from("publishSubscribeChannel")
                .handle("publishSubscribeMessageHandler", "handleMessage")
                .get();
    }
}
